﻿@using XRM.Security.DataAccess.Helpers
@using XRM.Security.WebUI.Models.Home
@using XRM.Security.WebUI.Security
@using XRM.Security.WebUI.Enums
@using XRM.Security.DataAccess.Enums
@model MainPageModel

@functions {

    readonly string[] userRoles = UserPrincipal.Current.Roles;
    private bool IsUserInRole(IEnumerable<string> roles)
    {
        return roles.Intersect(userRoles).Any();
    }
}

@{
    ViewBag.Title = "Главная";
    ViewBag.HideHeader = true;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-6 col-md-6" style="min-width: 510px;">
        <div class="panel @Model.RequestsPanelColor" style="margin:15px 0 15px 15px;">
            <div class="panel-heading">
                <div class="row">
                    <div class="col-xs-3">
                        <i class="fa fa-list-alt fa-5x"></i>
                    </div>
                    <div class="col-xs-9 text-right">
                        <div class="huge">@Model.OpenRequestCount</div>
                        <div>Количество открытых заявок</div>
                    </div>
                </div>
            </div>
            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSertificateEditor.ToString(),
                                    UserRoles.UsersReestrSkziEditor.ToString(), UserRoles.UsersReestrSoftwareEditor.ToString() }))
            {
            <a href="@Url.Action("Index", "Request")">
                <div class="panel-footer">
                    <span class="pull-left">Просмотреть</span>
                    <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                    <div class="clearfix"></div>
                </div>
            </a>
            }
        </div>
    </div>
    <div class="col-lg-6 col-md-6" style="min-width: 510px;">
        <div class="panel @Model.CertificatesPanelColor" style="margin:15px 0 15px 15px;">
            <div class="panel-heading">
                <div class="row">
                    <div class="col-xs-2">
                        <i class="fa fa-file-text-o fa-5x"></i>
                    </div>
                    <div class="col-xs-10 text-right">
                        <div class="huge">@Model.ExpiredCertificateCount</div>
                        <div>Количество сертификатов, истекающих через 30 дней</div>
                    </div>
                </div>
            </div>
            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSertificateEditor.ToString() }))
            {
            <a href="@Url.Action("Index", "CertRegister", new {expireDay = DataModelUtils.SoonExpireDaysCount})">
                <div class="panel-footer">
                    <span class="pull-left">Просмотреть</span>
                    <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                    <div class="clearfix"></div>
                </div>
            </a>
            }
        </div>
    </div>
</div>
